package cn.button;

import cn.entity.AccessToken;
import cn.entity.WechatAccountConfig;
import cn.util.HttpUtil;
import cn.util.Wechat;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class TestButton {

    public static void main(String[] args) {
        newButton();
    }

    /**
     * 公众号自定义菜单
     */
    public static void newButton(){
        String urls = "http://am68t5.natappfree.cc/wm315-publish/api/wx/redirectUrl";

        //创建一级菜单
        Button buttons = new Button();
        List<AbstractButton> button = new ArrayList<>();
        //一级菜单中的第一个按钮
        ClickButton clickButton = new ClickButton("千锋");
        clickButton.setKey("1");
        //一级菜单中的第二个按钮
        ViewButton viewButton = new ViewButton("个人中心",urls);
        //一级菜单中的第三个按钮（二级菜单）
        SubButton subButton = new SubButton("更多");
        List<AbstractButton> subButtons = new ArrayList<>();
        //二级菜单的第一个按钮
        subButtons.add(new ViewButton("百度","http://www.baidu.com"));
        //二级菜单的第二个按钮
        subButtons.add(new PhotoOrAlbumButton("上传图片","2"));
        subButton.setSub_button(subButtons);
        button.add(clickButton);
        button.add(viewButton);
        button.add(subButton);
        buttons.setButton(button);

        String s = JSONObject.toJSONString(buttons);
        System.out.println(s);

        String appId = "wx28f50c8a08e5468b";
        String appSecret = "27b2530f39b240763642405e4a033cdb";
        AccessToken accessToken = Wechat.getToken(appId, appSecret);

        String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN".replace("ACCESS_TOKEN",accessToken.getAccess_token());
        System.out.println(url);
        //发送请求
        String post = HttpUtil.doPost(url, s);
        System.out.println(post);
    }

}
